package net.jltec.view.adapter;

import java.util.List;

import net.jltec.view.R;
import net.jltec.view.bean.Task;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TaskDetailListAdapter extends BaseAdapter {
	
	private List<Task> tasks;
	private Context context;
	private LayoutInflater mInflater;
	
	
	public TaskDetailListAdapter(Context ctx, List<Task> tasks) {
		this.context = ctx;
		this.tasks=tasks;
		mInflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		

	}

	@Override
	public int getCount() {
		return tasks.size();
	}

	@Override
	public Task getItem(int position) {
		return tasks.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;

		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.main_task_item, null);
			holder = new Holder();

			TextView taskWiidText = (TextView) convertView.findViewById(R.id.task_wiid_text);
			holder.wiidText = taskWiidText;
			
			TextView noteText = (TextView) convertView.findViewById(R.id.task_note_text);
			holder.noteText = noteText;
			
			TextView nodeNameText = (TextView) convertView.findViewById(R.id.task_nodename_text);
			holder.nodeNameText = nodeNameText;
			
			
			
			TextView dtText = (TextView) convertView.findViewById(R.id.task_dt_text);
			holder.dtText = dtText;

			ImageView taskImage = (ImageView) convertView.findViewById(R.id.task_image);
			holder.taskImage =taskImage;

			

			convertView.setTag(holder);

		} else {
			holder = (Holder) convertView.getTag();
		}

		 holder.taskImage.setImageResource(R.drawable.task_flow);
		 holder.wiidText.setText("流水号:"+getItem(position).wiid);
		 
		 holder.nodeNameText.setText("审批节点:"+getItem(position).nodename);
		 
		 
		 holder.dtText.setText(getItem(position).createdt);
		 holder.noteText.setText((getItem(position).note));
		 
		 
		 
		return convertView;
	}
	
	
	public void addTask(Task task){
		this.tasks.add(task);
	}

	
	static class Holder {
		ImageView taskImage;
		TextView wiidText;
		TextView nodeNameText;
		TextView noteText;
		TextView mainText;
		TextView dtText;
	}
}
